package com.springmvc.heandler;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 通过处理器Handler来处理 将所有异常都获取到 转发的指定的页面
 */
//@Component
public class MyHandlerExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
                                         Object handler, Exception ex) {
        System.out.println("通过处理器处理。。。。");
        ModelAndView mv = new ModelAndView();
        mv.setViewName("error");
        mv.addObject("msg",ex);
        return mv;
    }
}
